package com.example.xposedtest.xposed;

import android.util.Log;
import com.example.xposedtest.utils.StepConfigUtils;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class StepHook {
    private static final String TAG = "StepHook";

    public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
        try {
            // 仅对微信生效
            if (!"com.tencent.mm".equals(lpparam.packageName)) {
                return;
            }

            // 微信步数处理类（不同版本可能有变化，这里是通用类名）
            Class<?> stepCounterClass = XposedHelpers.findClass(
                    "com.tencent.mm.plugin.fitness.a.b",  // 微信运动核心类（需根据版本调整）
                    lpparam.classLoader
            );

            // Hook微信获取步数的方法（如getStepCount）
            // 在StepHook中添加对m71.a类setStep方法的Hook
            Class<?> stepUIClass = XposedHelpers.findClass("m71.a", lpparam.classLoader);
            XposedBridge.hookAllMethods(stepUIClass, "setStep", new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    // 获取步数数据模型b对象
                    Object stepData = param.args[0];
                    if (stepData == null) return;

                    // 1. 修改显示的步数文本
                    XposedHelpers.setObjectField(stepData, "f277079a", "22222步");
                    // 2. 修改图标状态（比如强制显示“达标”图标，对应R.drawable.brt）
                    XposedHelpers.setIntField(stepData, "f277080b", 1); // 1对应brt图标
                }
            });

        } catch (Throwable e) {
            XposedBridge.log("StepHook 错误: " + e.getMessage());
            Log.e(TAG, "Hook失败", e);
        }
    }
}